package com.zy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SentinelGateway {
    public static void main(String[] args) {
        SpringApplication.run(SentinelGateway.class, args);
//        blockHandler();
    }

    // 限流异常处理
    public static void blockHandler() {
        // 重定向
//        GatewayCallbackManager.setBlockHandler(new RedirectBlockRequestHandler("https://baidu.com"));

        // 自定义
//        GatewayCallbackManager.setBlockHandler((serverWebExchange, throwable) -> {
//            Map<String, Object> map = new HashMap<>();
//            map.put("uri", serverWebExchange.getRequest().getURI());
//            map.put("message", "访问量过大，请稍后重试");
//            return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS).contentType(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(map));
//        });
    }
}
